/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function cekNama(nama){
    var reg = /^[A-Za-z\s]{5,}$/g;
    if(reg.test(nama))
    {
        document.getElementById("cek_nama").innerHTML = "Nama Valid";
        document.getElementById("cek_nama").style.color ="green";
    }
    else
    {
        document.getElementById("cek_nama").innerHTML = "Nama invalid, minimal 5 karakter (huruf dan spasi)";
        document.getElementById("cek_nama").style.color ="red";
    }
}

function cekUserName(username){
    var reg = /^[\w\.]{5,}$/g;
    if(reg.test(username))
    {
        document.getElementById("cek_username").innerHTML = "Username Valid";
        document.getElementById("cek_username").style.color ="green";
    }
    else
    {
        document.getElementById("cek_username").innerHTML = "Username invalid, minimal 5 karakter (huruf, angka, titik, underscore)";
        document.getElementById("cek_username").style.color ="red";
    }
}

function cekPassword(password){
    var reg = /^.{6,}$/;
    if(reg.test(password)){
        document.getElementById("cek_password").innerHTML = "Password Valid";
        document.getElementById("cek_password").style.color ="green";
    }
    else{
        document.getElementById("cek_password").innerHTML = "Password invalid, minimal 6 karakter";
        document.getElementById("cek_password").style.color ="red";
    }
}

function cekRePassword(rePassword){
    if(rePassword == document.getElementById("password").value && rePassword.length > 5){
        document.getElementById("cek_rePassword").innerHTML="Ulangi Password Valid";
        document.getElementById("cek_rePassword").style.color ="green";
    }
    else{
        document.getElementById("cek_rePassword").innerHTML="Ulang Password invalid, harus sama dengan password";
        document.getElementById("cek_rePassword").style.color ="red";
    }
}

function cekEmail(email){
    //   var reg = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
    var reg = /^[\w\.]{5,}@[\w\.]+\.[\w\.]+\.[\w\.]+/i;
    if(reg.test(email)){
        document.getElementById("cek_email").innerHTML = "Email Valid";
        document.getElementById("cek_email").style.color ="green";
    }
    else{
        document.getElementById("cek_email").innerHTML = "Email invalid, min. 5 karakter (huruf, angka, titik, underscore), 2 level";
        document.getElementById("cek_email").style.color ="red";
    }
}

function cekFoto(namaFile){
    var reg = /\.(png|bmp|jpg|jpeg)$/i;
    if(reg.test(namaFile)){
        document.getElementById("cek_foto").innerHTML = "File foto Valid";
        document.getElementById("cek_foto").style.color ="green";
    }
    else{
        document.getElementById("cek_foto").innerHTML = "File foto invalid, harus berformat \".jpg\", \".bmp\", \".jpeg\", atau \".png\"";
        document.getElementById("cek_foto").style.color ="red";
    }
}

function cekLokasi(lokasi){
    var reg = /^.{6,}$/;
    if(reg.test(lokasi)){
        document.getElementById("cek_lokasi").innerHTML = "Lokasi Valid";
        document.getElementById("cek_lokasi").style.color ="green";
    }
    else{
        document.getElementById("cek_lokasi").innerHTML = "Lokasi invalid, minimal 5 karakter";
        document.getElementById("cek_lokasi").style.color ="red";
    }
}

function cekDeskripsi(deskripsi){
    var reg = /^.{5,}$/;
    if(reg.test(deskripsi)){
        document.getElementById("cek_deskripsi").innerHTML = "Deskripsi Valid";
        document.getElementById("cek_deskripsi").style.color ="green";
    }
    else{
        document.getElementById("cek_deskripsi").innerHTML = "Deskripsi invalid, minimal 5 karakter";
        document.getElementById("cek_deskripsi").style.color ="red";
    }
}

function cekKataKunci(kataKunci){
    var reg = /^.{3,}/;
    if(reg.test(kataKunci)){
        document.getElementById("cek_kataKunci").innerHTML = "Kata kunci Valid";
        document.getElementById("cek_kataKunci").style.color ="green";
    }
    else{
        document.getElementById("cek_kataKunci").innerHTML = "Kata kunci invalid, minimal 3 karakter";
        document.getElementById("cek_kataKunci").style.color ="red";
    }
}

function cekTanggal(tanggal){
    var reg = /(?:0[1-9]|[12][0-9]|3[01])\-(?:0[1-9]|1[0-2])\-(?:19|20\d{2})/;
    if(reg.test(tanggal)){
        document.getElementById("cek_tanggalLahir").innerHTML = "Tanggal Valid";
        document.getElementById("cek_tanggalLahir").style.color = "green";
        
    }
    else{
        document.getElementById("cek_tanggalLahir").innerHTML = "Tanggal invalid, formatnya YYYY-MM-DD";
        document.getElementById("cek_tanggalLahir").style.color = "red";
        
    }

}

/*
document.getElementById("lontong").onclick = function(){
    document.location = "upload.html";
}*/